package com.android.vgongyi.utils;

import java.util.ArrayList;

import android.content.Context;
import android.net.Uri;

import com.android.vgongyi.dao.BaseDAO;
import com.android.vgongyi.dao.CommentDAO;
import com.android.vgongyi.dao.CommonDAO;
import com.android.vgongyi.dao.FavorateDAO;
import com.android.vgongyi.dao.ImageDAO;
import com.android.vgongyi.entity.CommentEntity;
import com.android.vgongyi.entity.CommonEntity;
import com.android.vgongyi.entity.ImageEntity;

public class DBUtil {

	public static boolean checkisExist(Uri uri,String where,Context context){
		if(uri.equals(BaseDAO.URI_COMMON)){
			CommonDAO commonDAO = new CommonDAO(context);
			ArrayList<CommonEntity> list = commonDAO.query(null, where, null,null);
			if(list.size() == 0){
				return false;
			}else{
				return true;
			}
		}else if(uri.equals(BaseDAO.URI_COMMENT)){
			CommentDAO commentDAO = new CommentDAO(context);
			ArrayList<CommentEntity> list = commentDAO.query(null, where, null,null);
			if(list.size() == 0){
				return false;
			}else{
				return true;
			}
		}else if(uri.equals(BaseDAO.URI_FAVORITE)){
			FavorateDAO favorateDAO = new FavorateDAO(context);
			ArrayList<CommonEntity> list = favorateDAO.query(null, "id="+"'"+where+"'", null,null);
			if(list.size() == 0){
				return false;
			}else{
				return true;
			}
		}else if(uri.equals(BaseDAO.URI_IMAGE)){
			ImageDAO imageDAO = new ImageDAO(context);
			ArrayList<ImageEntity> list = imageDAO.query(null, where, null,null);
			if(list.size() == 0){
				return false;
			}else{
				return true;
			}
		}
		return false;
	}
}
